﻿<%@ Page Language="C#" AutoEventWireup="true" Culture="en-GB" CodeFile="Paybles.aspx.cs"
    Inherits="Main_Reports_Accounts_OutStandings_Paybles" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<%@ Register Src="~/User Controls/PageHeading.ascx" TagName="Heading" TagPrefix="acc" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Outstanding Payables</title>
    <link href="../../../../Styles/accounts.css" rel="stylesheet" type="text/css" />

    <script type="text/javascript">
        function Validation() {
            var flag = true;
            var txtTodate = document.getElementById("txtToDate").id;
            if (document.getElementById("txtToDate").value == '') {
                alert('Specify To date');
                flag = false;
            }
            else {
                if (!isDate(txtTodate)) {
                    flag = false;
                }
            }
            return flag;
        }
        function isDate(txtDateId) {
            // date length should be 10 characters - no more, no less            
            var Ctrl = document.getElementById(txtDateId);
            var txtDate = Ctrl.value;
            var flag = true;

            // extract day, month and year from the txtDate string
            // expected format is dd/mm/yyyy
            var day = '';
            var month = '';
            var year = '';
            var dateArray = new Array();
            var count = 0;
            for (var j = 0; j < txtDate.length; j++) {
                var chara = txtDate.charAt(j);
                if (chara == '/') {
                    count += 1;
                }
            }
            if (count != 2) {
                alert('Invalid date !');
                return false;
            }
            dateArray = txtDate.split("/");


            day = dateArray[0];
            month = dateArray[1];
            year = dateArray[2];


            if (year.length != 4) {
                alert('Invalid date !');
                return false;
            }
            var finYear = document.getElementById("hidFinyear").value;
            if (month >= 4 && year != parseInt(finYear)) {
                alert('Date Should be between 01/04/' + finYear + ' and 31/03/' + (parseInt(finYear) + 1));
                return false;
            }
            else if (month < 4 && year != (parseInt(finYear) + 1)) {
                alert('Date Should be between 01/04/' + finYear + ' and 31/03/' + (parseInt(finYear) + 1));
                return false;
            }



            if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
                if (day > 31) {
                    alert('Date Should not be Greater than 31');
                    Ctrl.focus();
                    flag = false;
                }
            }
            //for have only 30 day
            else if (month == 4 || month == 6 || month == 9 || month == 11) {
                if (day > 30) {
                    alert('Date Should not be Greater than 30');
                    Ctrl.focus();
                    flag = false;
                }
            }
            //for Febuary 
            else if (month == 2) {
                var leap = year % 4;
                if (leap == 0) {
                    if (day > 29) {
                        alert('february have only 29 days');
                        Ctrl.focus();
                        flag = false;
                    }
                }
                else {
                    if (day > 28) {
                        alert('february have only 28 days');
                        Ctrl.focus();
                        flag = false;
                    }
                }
            }
            else if (month > 12) {
                alert('Invalid Date');
                Ctrl.focus();
                flag = false;
            }
            // otherwise return true
            return flag;
        }
        function printPartOfPage() {


            var printDiv = document.getElementById("divPrint").innerHTML;
            var windowUrl = 'about:blank';
            var uniqueName = new Date();
            var windowName = 'Print' + uniqueName.getTime();
            var printWindow = window.open(windowUrl, windowName, 'left=5000,top=5000,width=0,height=0');
            printWindow.document.write(printDiv);
            printWindow.document.close();
            printWindow.focus();
            printWindow.print();
            printWindow.close();
            return false;
        }
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="scriptmanager1" runat="server" EnablePageMethods="true">
    </asp:ScriptManager>
    <asp:HiddenField ID="hidFinyear" runat="server" />
    <div class="divmain">
        <acc:Heading ID="pagehead" runat="server" HeadingText="Payables" />
    </div>
    <table>
        <tr>
            <td>
                <asp:LinkButton ID="lnkchangedate" runat="server" Text="ChangeDate "></asp:LinkButton>
                &nbsp;<asp:HyperLink ID="hpr" NavigateUrl="#" runat="server" Text="Print" onclick=" return printPartOfPage();"></asp:HyperLink>
                &nbsp;<asp:LinkButton ID="lnkback" runat="server" Text="Back" 
                    onclick="lnkback_Click"></asp:LinkButton>
            </td>
        </tr>
    </table>
    <div id="divPrint">
        <table width="100%">
            <tr>
                <td align="center">
                    <asp:Label ID="lblcompname" Font-Bold="true" Font-Size="Small" runat="server"></asp:Label>
                </td>
            </tr>
            <tr align="center">
                <td>
                    <asp:Label ID="lblheading" runat="server">
                    </asp:Label>
                </td>
            </tr>
            <tr>
                <div id="div1" style="width: 100%;">
                    <asp:GridView ID="grdDisplay" ShowFooter="true" OnRowDataBound="rowdatabound" runat="server"
                        AutoGenerateColumns="false" Style="width: 100%;"  DataKeyNames="TransactionTypeID,TransactionDate,TransactionID" CssClass="gridview">
                        <Columns>
                            <asp:BoundField HeaderText="Date" DataField="TransactionDate" ItemStyle-Wrap="false"
                                DataFormatString="{0:dd-MMM-yyyy}" ItemStyle-Width="9%" />
                            <asp:BoundField HeaderText="Ref No." DataField="ReferenceNumber" ItemStyle-Width="11%"
                                ItemStyle-Wrap="false" />
                            <%--<asp:BoundField HeaderText="Voucher No." DataField="TransactionNumber" ItemStyle-Wrap="false"
                                ItemStyle-Width="10%" />--%>
                                <asp:TemplateField HeaderText="Voucher No.">
                            <ItemTemplate>
                            <asp:HyperLink ID="hprvoucherno" NavigateUrl="#" runat="server" Text=<%#Eval("TransactionNumber") %>></asp:HyperLink>
                            </ItemTemplate>
                            </asp:TemplateField>
                            <asp:BoundField HeaderText="Transaction" DataField="TransactionType" ItemStyle-Wrap="false"
                                ItemStyle-Width="15%" />
                            <asp:BoundField HeaderText="Party's Name" DataField="PartyName" ItemStyle-Wrap="false"
                                ItemStyle-Width="11%" />
                            <asp:BoundField HeaderText="Original Amount" DataField="OriginalAmount" ItemStyle-Width="5%"
                                ItemStyle-HorizontalAlign="Right" />
                            <asp:BoundField HeaderText="" DataField="OriginalAmountCrDr" />
                            <asp:BoundField HeaderText="Received Paid Amount" DataField="DiffAmount" ItemStyle-Width="10%"
                                ItemStyle-HorizontalAlign="Right" />
                            <asp:BoundField HeaderText="Pending Amount" DataField="PendingAmount" ItemStyle-Width="10%"
                                ItemStyle-HorizontalAlign="Right" />
                            <asp:BoundField HeaderText="Due on" DataField="DueOn" DataFormatString="{0:dd-MMM-yyyy}"
                                ItemStyle-Wrap="false" ItemStyle-Width="9%" ItemStyle-HorizontalAlign="Center" />
                            <asp:BoundField HeaderText="Due Days" DataField="DueDays" ItemStyle-HorizontalAlign="Right"
                                ItemStyle-Width="3%" />
                            <asp:BoundField HeaderText="Reamrks" DataField="Remarks" ItemStyle-Wrap="true" ItemStyle-Width="7%" />
                        </Columns>
                    </asp:GridView>
                </div>
            </tr>
        </table>
    </div>
    <asp:Panel ID="panel" CssClass="modalPopup" runat="server" Width="150px" Height="160px"
        Style="margin-left: 10%; display: none">
        <table style="margin-left: 25%; margin-right: 50%; width: 100%; margin-top: 5%;">
            <tr>
                <td>
                    To :&nbsp;&nbsp<asp:TextBox ID="txtToDate" Width="69%" CssClass="input" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                </td>
            </tr>
            <tr align="center">
                <td>
                    <asp:Button ID="btnShow"  runat="server" CssClass="button" Text="Show" OnClick="show" OnClientClick="return Validation();" />
                    <asp:Button ID="btnCancel" runat="server" CssClass="button" Text="Cancel" />
                </td>
            </tr>
        </table>
    </asp:Panel>
    <ajaxToolkit:ModalPopupExtender ID="modalpopup" BackgroundCssClass="modalBackground"
        runat="server" TargetControlID="lnkchangedate" PopupControlID="panel" CancelControlID="btnCancel">
    </ajaxToolkit:ModalPopupExtender>
    </form>
</body>
</html>
